from linkedList import ListNode, list_to_node, node_to_list


class Solution:
    def reverseList(self, head: ListNode) -> ListNode:
        if not head:
            return head
        node = []
        while head:
            node.append(head)
            head = head.next
        for i in range(len(node) - 1, 0, -1):
            node[i].next = node[i - 1]
        node[0].next = None
        return node[-1]


if __name__ == '__main__':
    a = Solution()
    print(a.reverseList(list_to_node([1, 2, 3, 4, 5])))
